
package com.idealighter.game.games.zjh.struct;

import com.idealighter.game.games.zjh.util.ZjhCardsTypeGetter;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

/**
 * 炸金花的3张牌 .
 * 
 * @date 2016年6月27日 上午11:27:56
 *
 */
@Data
public class ZjhCards {
  // 玩家的牌数据
  private final List<ZjhCard> cards;
  // 当前牌型
  private final ZjhCardsType type;
  // 最大牌
  private final ZjhCard maxCard;
  // 中间
  private final ZjhCard midCard;
  // 最小牌
  private final ZjhCard minCard;

  /**
   * 构造函数 .
   * 
   * @param cards .
   */
  public ZjhCards(List<ZjhCard> cards) {
    super();
    this.cards = cards;
    this.type = ZjhCardsTypeGetter.geCardsType(cards);

    List<ZjhCard> cardsTmp = new ArrayList<>(cards);
    ZjhCard maxCard = cardsTmp.get(0);

    for (int i = 0; i < cardsTmp.size(); i++) {
      ZjhCard card = cardsTmp.get(i);
      if (card.getPower() > maxCard.getPower()) {
        maxCard = card;
      }
    }

    this.maxCard = maxCard;

    cardsTmp.remove(maxCard);
    ZjhCard first = cardsTmp.get(0);
    ZjhCard second = cardsTmp.get(1);

    if (first.getPower() < second.getPower()) {
      this.minCard = first;
      this.midCard = second;
    } else {
      this.minCard = second;
      this.midCard = first;
    }
  }
}
